var i = getApp(), t = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js"), a = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js");

Page({
    data: {
        winWidth: i.globalData.windowWidth,
        curSize: "",
        telephone: ""
    },
    onLoad: function(t) {
        var a = this, n = i.globalData.isLogin;
        this.setData({
            isLogin: n
        }, function() {
            n || a.login();
        });
    },
    onShow: function() {
        null !== a._cb && (this.setData({
            isLogining: !1
        }), a._cb = null);
    },
    login: function() {
        var t = this;
        i.globalData.isLogin || this.data.isLogining || this.setData({
            isLogining: !0
        }, function() {
            a.login(function(i) {
                t.setData({
                    isLogining: !1,
                    isLogin: !0
                });
            });
        });
    },
    onShareAppMessage: function() {},
    changeSize: function(i) {
        this.setData({
            curSize: i.currentTarget.dataset.size
        });
    },
    handleInput: function(i) {
        var t = {};
        t[i.currentTarget.dataset.type] = i.detail.value, this.setData(t);
    },
    submit: function() {
        var a = this;
        if (i.globalData.isLogin) {
            if (!this.data.isLoading) {
                var n = this.data.curSize;
                if (n) {
                    var e = this.data.telephone.trim();
                    e ? /^1(3|4|5|6|7|8|9)\d{9}$/.test(e) ? (this.setData({
                        isLoading: !0
                    }), wx.showLoading(), t.post("/v1/ali/gratisOrder", {
                        size: n,
                        telephone: e,
                        user_id: i.globalData.user.user_id
                    }).then(function(i) {
                        if (wx.hideLoading(), a.setData({
                            isLoading: !1
                        }), 1001 === i.data.code) {
                            var t = i.data.response.data;
                            wx.navigateTo({
                                url: "/pages/pay/pay?from=activity&orderId=" + t.order_id + "&price=" + t.order_total_paid / 100
                            });
                        }
                    }).catch(function() {
                        wx.hideLoading(), a.setData({
                            isLoading: !1
                        });
                    })) : wx.showToast({
                        title: "请输入正确的手机号码",
                        icon: "none"
                    }) : wx.showToast({
                        title: "请输入手机号码",
                        icon: "none"
                    });
                } else wx.showToast({
                    title: "请选择衣服尺寸",
                    icon: "none"
                });
            }
        } else this.login();
    }
});